package com.wzq.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzq.dao.pojo.PageBean;
import com.wzq.dao.pojo.R;
import com.wzq.dao.pojo.Sum;
import com.wzq.dao.pojo.Type;
import com.wzq.mapper.Summapper;
import com.wzq.service.ISumService;
import com.wzq.service.ITypeService;
import com.wzq.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/admin/sum")
public class AdminSumController {

    @Autowired
    ISumService iSumService;
    @RequestMapping("/list")
    public R list(@RequestBody PageBean pageBean){
        System.out.println(pageBean);
        String query=pageBean.getQuery().trim();
        Page<Sum> page=new Page<>(pageBean.getPageNum(),pageBean.getPageSize());
        Page<Sum> pageResult = iSumService.page(page, new QueryWrapper<Sum>().like(StringUtil.isNotEmpty(query), "sum", query));
        Map<String,Object> map=new HashMap<>();
        map.put("SumList",pageResult.getRecords());
        map.put("total",pageResult.getTotal());
        return R.ok(map);
    }

    @RequestMapping("/update/{sumvaule}")
    public R save(@PathVariable Integer sumvaule){
        Sum sum = new Sum(1, (Integer) sumvaule);
        iSumService.updateById(sum);

        return R.ok();
    }

    @GetMapping("/{id}")
    public R findById(@PathVariable(value = "id")Integer id){
        Sum sum = iSumService.getById(id);
        Map<String,Object> map=new HashMap<>();
        map.put("sum",sum);
        return R.ok(map);
    }

    @GetMapping("/delete/{id}")
    public R delete(@PathVariable(value = "id")Integer id){
        iSumService.removeById(id);
            return R.ok();
        }


    @RequestMapping("/listAll")
    public R listAll(){

        QueryWrapper queryWrapper=new QueryWrapper<Sum>();
        queryWrapper.in("id",7,8,9);
        Map<String,Object> map=new HashMap<>();
        map.put("SumList",iSumService.list(queryWrapper));
        return R.ok(map);
    }


}

